package io.renren.modules.heartself.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.heartself.entity.HeartNewsEntity;
import io.renren.modules.heartself.service.HeartNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author jlk
 * @email sunlightcs@gmail.com
 * @date 2021-11-19 17:07:41
 */
@RestController
@RequestMapping("heartSelf/heartNews")
public class HeartNewsController {
    @Autowired
    private HeartNewsService heartNewsService;

    /**
     * 列表
     */
    @GetMapping("/queryNewsList")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = heartNewsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        HeartNewsEntity heartNews = heartNewsService.getById(id);

        return R.ok().put("heartNews", heartNews);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody HeartNewsEntity heartNews) {
        heartNewsService.save(heartNews);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody HeartNewsEntity heartNews) {
        heartNewsService.updateById(heartNews);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        heartNewsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
